import Vue from 'vue';
import Progress from '@/components/widget/Progress';

let cmp = undefined;

const init = () => {
    close();
    cmp = new Vue(Progress);
    document.body.appendChild(cmp.$mount().$el);
    return cmp;
};

const close = () => {
    if (cmp !== undefined) {
        try {
            cmp.close();
        } catch (e) {
            console.info(e);
        }
    }
    cmp = undefined;
};

export const linear = {
    start(color) {
        init().show(color);
    },
    end() {
        init().close();
    }
};

Vue.prototype.$linear = linear;

export default linear;
